package com.example.arithmeticleetcode.leetcode.nov;

import java.util.*;

/**
 * @program: arithmetic-leetcode
 * @description: https://leetcode-cn.com/problems/sequential-digits/
 * @author: FangZhen
 * @create: 2020-11-25 09:24
 **/
public class Demo17 {



    public List<Integer> sequentialDigits(int low, int high) {
        List<Integer> list = new ArrayList<>();
        return list;

    }


    /**
     * 统计位数为偶数的数字
     *
     * @param nums
     * @return
     */
    public int findNumbers(int[] nums) {
        int count = 0;
        for (int num : nums) {
            if (String.valueOf(num).length() % 2 == 0) {
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,3,4,4,5,6};
        isPossibleDivide(arr, 4);
    }

    public static boolean isPossibleDivide(int[] nums, int k) {
        if (nums.length % k != 0) return false;
        if (k == 1) return true;
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        Arrays.sort(nums);
        for (int num : nums) {
            int v = map.get(num);
            if (v == 0) continue;
            map.put(num, --v);
            for (int j = 1; j < k; j++) {
                int value = map.get(++num);
                if (value == 0) return false;
                map.put(num, --value);
            }
        }
        return true;

    }
}
